package org.reenscape.packet;
import org.reenscape.model.*;
import org.reenscape.*;
import org.reenscape.skill.*;
import org.reenscape.updater.*;
public class PacketNpc {

	/**
	* Clicking on the NPC. Talking.
	*/
		public void FirstClick(PacketParser p3){
			int Slot = p3.inStream.readSignedWordBigEndian();
			int ID = Server.npcUpdater.npcs[Slot].npcType;
			int X = Server.npcUpdater.npcs[Slot].absX;
			int Y = Server.npcUpdater.npcs[Slot].absY;
			p3.faceNPC(Slot);
			
			if(p3.playerRights == 3) p3.sendMessage("N-C1 - "+Slot+","+ID+","+X+","+Y);
			
			if(ID == 319) {
				if(p3.IsItemInBag(303)) {
					Skill.fishing.init(p3, 317, 50, 0x26D);
				} else {
					p3.sendMessage("You need a "+p3.GetItemName(303)+" to fish here.");
				}
			}
		}
	
	/**
	* Clicking on the NPC. Trading and Thieving.
	*/
		public void SecondClick(PacketParser p3){
			int Slot = p3.inStream.readUnsignedWordBigEndianA();
			int ID = Server.npcUpdater.npcs[Slot].npcType;
			int X = Server.npcUpdater.npcs[Slot].absX;
			int Y = Server.npcUpdater.npcs[Slot].absY;
			p3.faceNPC(Slot);
			
			if(p3.playerRights == 3) p3.sendMessage("N-C2 - "+Slot+","+ID+","+X+","+Y);
			ShopShow.open(ID, p3);
			Skill.thieving.Pickpocket(ID, p3, Slot);
			if(ID == 494 || ID == 495) p3.openUpBank();
			//Check for fishing
			
			//Any other NPCs with second click.
		}
	
	/**
	* Clicking on the NPC. Miscellanious/Multiple uses.
	*/
		public void ThirdClick(PacketParser p3){
			int Slot = p3.inStream.readSignedWord();
			int ID = Server.npcUpdater.npcs[Slot].npcType;
			int X = Server.npcUpdater.npcs[Slot].absX;
			int Y = Server.npcUpdater.npcs[Slot].absY;
			p3.faceNPC(Slot);
			
			if(p3.playerRights == 3) p3.sendMessage("N-C3 - "+Slot+","+ID+","+X+","+Y);
			
			//NPCs with third click. (I know like Aubury and that bunch use this for teleporting to the Rune Essence mines.)
		}
	/**
	* Advancing the chat when talking to an NPC.
	*/
		public void ChatAdvance(PacketParser p3){
			if (Server.dialogueHandler.DialogueType[p3.NpcDialogue] == 1 || Server.dialogueHandler.DialogueType[p3.NpcDialogue] == 3) {
				p3.NpcDialogue = Server.dialogueHandler.DialogueNextDia[p3.NpcDialogue];
				p3.NpcDialogueSend = false;
				if (p3.NpcDialogue == 0) {
					p3.RemoveAllWindows();
				}
			}
			//Below is a fix for any dialogue thats forced, the reason for this one is the skill levelup thing. Didn't remove on 'Click to continue'.
			else {
				p3.NpcDialogue = 0;
				p3.NpcDialogueSend = false;
				p3.RemoveAllWindows();
			}
		}
		
	/**
	* Clicking attack on an NPC.
	*/
		public void Attack(PacketParser p3){
			int Slot = p3.inStream.readUnsignedWordA();
			p3.MeleeNpcSlot = Slot;
			p3.faceNPC(Slot);
		}
		
	/**
	* Using a spell on an NPC.
	*/
		public void Spell(PacketParser p3){
			int Index = p3.inStream.readSignedWordBigEndianA();
			int ID = p3.inStream.readSignedWordA();
			p3.resetWalkingQueue();
			p3.faceNPC(Index);
			//Skill.magic.castOnNPC(p3, ID, Index);
		}
		
		public void NPCDialogue(String s, int npc, PacketParser p3){ // One line
			p3.sendFrame200(4883, 591);
			p3.sendFrame126(p3.GetNpcName(npc), 4884);
			p3.sendFrame126(s, 4885);
			p3.sendFrame126("Click here to continue.", 4886);
			p3.sendFrame75(npc, 4883);
			p3.sendFrame164(4882);
			p3.NpcDialogueSend = true;
		}

		public void NPCDialogue(String s, String s2, int npc, PacketParser p3){ // Two line
			p3.sendFrame200(4888, 591);
			p3.sendFrame126(p3.GetNpcName(npc), 4889);
			p3.sendFrame126(s, 4890);
			p3.sendFrame126(s2, 4891);
			p3.sendFrame126("Click here to continue.", 4892);
			p3.sendFrame75(npc, 4888);
			p3.sendFrame164(4887);
			p3.NpcDialogueSend = true;
		}
		
		public void NPCDialogue(String s, String s2, String s3, int npc, PacketParser p3){ // Three lines
			p3.sendFrame200(4894, 591);
			p3.sendFrame126(p3.GetNpcName(npc), 4895);
			p3.sendFrame126(s, 4896);
			p3.sendFrame126(s2, 4897);
			p3.sendFrame126(s3, 4898);
			p3.sendFrame126("Click here to continue.", 4899);
			p3.sendFrame75(npc, 4894);
			p3.sendFrame164(4893);
			p3.NpcDialogueSend = true;
		}

		public void NPCDialogue(String s, String s2, String s3, String s4, int npc, PacketParser p3){ // Four lines
			p3.sendFrame200(4901, 591);
			p3.sendFrame126(p3.GetNpcName(npc), 4902);
			p3.sendFrame126(s, 4903);
			p3.sendFrame126(s2, 4904);
			p3.sendFrame126(s3, 4905);
			p3.sendFrame126(s4, 4906);
			p3.sendFrame126("Click here to continue.", 4907);
			p3.sendFrame75(npc, 4901);
			p3.sendFrame164(4900);
			p3.NpcDialogueSend = true;
		}
}